/*
 * igo: com.cctv.igo.admin.scheduler.ui.TriggerAction.java Create On 2011-5-3 下午11:21:27 By Q-Wang
 * $Revision: 1.2 $
 */
package com.ctvit.scheduler.ui;

import java.util.List;

import com.ctvit.scheduler.domain.QrtxTrigger;
import com.ctvit.scheduler.dto.Trigger;
import com.ctvit.scheduler.service.TriggerService;
import com.ctvit.framework.dao.Pager;
import com.ctvit.framework.struts2.ActionSupport;
import com.ctvit.framework.web.context.ContextHolder;

/**
 * @author <a href="mailto:apeidou@gmail.com">Q-Wang</a>
 *
 */
public class TriggerAction extends ActionSupport {

	private TriggerService triggerService = ContextHolder.getBean(TriggerService.class);

	private Pager<QrtxTrigger> pager;

	private Trigger trigger;

	private List<QrtxTrigger> items;

	private boolean cascade;

	/**
	 * @return the pager
	 */
	public Pager<QrtxTrigger> getPager() {
		return pager;
	}

	/**
	 * @param pager the pager to set
	 */
	public void setPager(Pager<QrtxTrigger> pager) {
		this.pager = pager;
	}

	/**
	 * @return the trigger
	 */
	public Trigger getTrigger() {
		return trigger;
	}

	/**
	 * @param trigger the trigger to set
	 */
	public void setTrigger(Trigger trigger) {
		this.trigger = trigger;
	}

	/**
	 * @return the items
	 */
	public List<QrtxTrigger> getItems() {
		return items;
	}

	/**
	 * @param items the items to set
	 */
	public void setItems(List<QrtxTrigger> items) {
		this.items = items;
	}

	/**
	 * @param cascade the cascade to set
	 */
	public void setCascade(boolean cascade) {
		this.cascade = cascade;
	}


	public String add() {
		trigger = null;
		return "add";
	}

	public String edit() {
		trigger = triggerService.get(trigger.getId());
		return "edit";
	}

	public String save() {
		triggerService.save(trigger);
		addActionMessage("计划任务 触发器'" + trigger.getName() + "'保存成功.");
		return list();
	}

	public String update() {
		triggerService.update(trigger);
		addActionMessage("计划任务 触发器'" + trigger.getName() + "'更新成功.");
		return list();
	}

	public String delete() {
		triggerService.delete(trigger.getId(), cascade);
		addActionMessage("计划任务 触发器'id=" + trigger.getId() + "'删除成功.");
		trigger = null;
		return list();
	}

	public String list() {
		if (pager==null) {
			pager = new Pager<QrtxTrigger>();
		}
		pager.setQuery(trigger);
		triggerService.list(pager);
		items = pager.getResult();
		return LIST;
	}
}
